package com.fesine.batch.controller;

import com.fesine.commons.util.ResponseUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by Fesine on 2016/1/9.
 */
@Controller
@RequestMapping("/area")
public class AreaController {

    protected final Log logger = LogFactory.getLog(this.getClass());

    @RequestMapping("/listArea")
    public void listArea(Integer id, HttpServletRequest request, HttpServletResponse response) throws Exception {
        //接收Client端传来的参数，交根据条件返回
        logger.debug("------>接受请求:" + id);
        String text;
        if (id == 1) {
            text = "{data:[{id:1,name:'东城区'},{id:2,name:'西城区'},{id:2,name:'海淀区'}]}";

        } else {
            text = "{data:[{id:1,name:'东城区'},{id:2,name:'西城区'},{id:2,name:'海淀区'}]}";
        }
        //request.setAttribute("data", text);
        ResponseUtils.outPut(response, text);
        //return "showUser";
    }

    @RequestMapping("/listCity")
    public void listCity(HttpServletRequest request, HttpServletResponse response) throws Exception {
        //request.setAttribute("data", "[{id:1,name:'北京'},{id:2,name:'上海'}]");
        logger.debug("------>接受请求:" + request);
        ResponseUtils.outPut(response, "{data:[{id:1,name:'北京'},{id:2,name:'上海'}]}");
        //return null;
    }
}
